/**
 * 商品报损查询管理初始化
 */
var GoodsDamageList = {
    id: "GoodsDamageListTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
GoodsDamageList.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '主键', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '商品编码', field: 'goodsCode', visible: true, align: 'center', valign: 'middle'},
        {title: '商品型号', field: 'goodsModel', visible: true, align: 'center', valign: 'middle'},
        {title: '商品名称', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
        {title: '报损数量', field: 'damageNumber', visible: true, align: 'center', valign: 'middle'},
        {title: '报损价格', field: 'damagePrice', visible: true, align: 'center', valign: 'middle'},
        {title: '报损总价', field: 'totalPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '商品计量单位', field: 'goodsUnit', visible: true, align: 'center', valign: 'middle'},
        {title: '创建者', field: 'createBy', visible: true, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createDate', visible: true, align: 'center', valign: 'middle'},
        {title: '更新者', field: 'updateBy', visible: true, align: 'center', valign: 'middle'},
        {title: '更新时间', field: 'updateDate', visible: true, align: 'center', valign: 'middle'},
        {title: '备注信息', field: 'remarks', visible: true, align: 'center', valign: 'middle'},
        {title: '删除标记（0：正常；1：删除）', field: 'delFlag', visible: true, align: 'center', valign: 'middle'},
        {title: '主键', field: 'damageId', visible: true, align: 'center', valign: 'middle'},
        {title: '商品id', field: 'goodsId', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
GoodsDamageList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length === 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        GoodsDamageList.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加商品报损查询
 */
GoodsDamageList.openAddGoodsDamageList = function () {
    var index = layer.open({
        type: 2,
        title: '添加商品报损查询',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/goodsDamageList/goodsDamageList_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看商品报损查询详情
 */
GoodsDamageList.openGoodsDamageListDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '商品报损查询详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/goodsDamageList/goodsDamageList_update/' + GoodsDamageList.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除商品报损查询
 */
GoodsDamageList.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/goodsDamageList/delete", function (data) {
            Feng.success("删除成功!");
            GoodsDamageList.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("goodsDamageListId", this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询商品报损查询列表
 */
GoodsDamageList.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    GoodsDamageList.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = GoodsDamageList.initColumn();
    var table = new BSTable(GoodsDamageList.id, "/goodsDamageList/list", defaultColunms);
    table.setPaginationType("client");
    GoodsDamageList.table = table.init();
});
